//
// Created by shen on 8/10/2024.
//

#ifndef TSAVPLAYER_AUDIODECODER_H
#define TSAVPLAYER_AUDIODECODER_H
#include "AudioRender.h"

#include "BaseDecoder.h"
static const uint64_t AUDIO_DST_CHANNEL_LAYOUT = AV_CH_LAYOUT_STEREO;
static const int AUDIO_DST_SAMPLE_RATE = 44100;

// ACC音频一帧采样数
static const int ACC_NB_SAMPLES = 1024;

// 音频编码通道数
static const int AUDIO_DST_CHANNEL_COUNTS = 2;
class AudioDecoder : public BaseDecoder{
public:
    AudioDecoder(char *url){
        Init(url, AVMEDIA_TYPE_AUDIO);
    }

    ~AudioDecoder(){
        UnInit();
    }


    void setAudioRender(AudioRender *audioRender){
        m_AudioRender=audioRender;
    }

//    setRe

public:
    virtual void OnDecoderReady();

    virtual void OnDecoderDone();

    virtual void OnFrameAvailable(AVFrame *frame);

    virtual void ClearCache();

private:

    const AVSampleFormat DST_SAMPLT_FORMAT = AV_SAMPLE_FMT_S16;
    AudioRender *m_AudioRender = nullptr;


    SwrContext *m_SwrContext= nullptr;

    uint8_t  *m_AudioOutBuffer = nullptr;
    //number of sample per channel
    int m_nbSamples=0;
    //dst frame data size
    int  m_DstFrameDataSze = 0;



};


#endif //TSAVPLAYER_AUDIODECODER_H
